<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}告警系统{% endblock %}</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <!-- 自定义CSS -->
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #15dcd9f9;
            --accent-color: #e74c3c;
            --light-color: #f8f9fa;
            --dark-color: #212529;
            --sidebar-width: 250px;
        }
        
        body {
            min-height: 100vh;
            overflow-x: hidden;
            background-color: #f5f7fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            display: flex;
            height: 100vh;
        }
        
        .sidebar {
            height: 100vh;
            width: var(--sidebar-width);
            background: linear-gradient(135deg, var(--primary-color), #1a2a3a);
            color: white;
            transition: all 0.3s;
            z-index: 100;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
            position: fixed;
            left: 0;
            top: 0;
        }
        
        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.85);
            transition: all 0.2s;
            border-radius: 0 30px 30px 0;
            margin: 5px 0;
            padding: 12px 20px;
        }
        
        .sidebar .nav-link:hover, .sidebar .nav-link.active {
            color: white;
            background-color: rgba(255, 255, 255, 0.15);
            transform: translateX(5px);
        }
        
        .sidebar .nav-link i {
            margin-right: 12px;
            width: 24px;
            text-align: center;
            font-size: 1.2rem;
        }
        
        .main-content {
            flex: 1;
            transition: all 0.3s;
            margin-left: var(--sidebar-width);
            padding: 15px; /* 减少内边距以增加可用空间 */
            display: flex;
            flex-direction: column;
            height: 100vh;
            overflow-y: scroll;
            background-color: #f5f7fa;
            /* 加宽主内容区域 */
            width: calc(100% - var(--sidebar-width));
        }
        
        .content-wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 100%;
            /* 移除高度限制并添加flex-grow */
            flex-grow: 1;
            padding: 0;
            margin-top: 0; /* 移除顶部外边距 */
        }
        
        .content-container {
            width: 100%;
            max-width: 95%; /* 使用百分比宽度代替固定值 */
            min-height: calc(100vh - 120px); /* 动态高度 */
            padding: 25px; /* 减少内边距 */
            background: white;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);

        }
        
        .sidebar-toggle {
            position: fixed;
            left: calc(var(--sidebar-width) + 10px);
            top: 15px;
            z-index: 99;
            display: none;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
        }
        
        @media (max-width: 992px) {
            .sidebar {
                margin-left: -250px;
                position: fixed;
            }
            
            .sidebar.show {
                margin-left: 0;
            }
            
            .main-content {
                margin-left: 0;
                width: 100%;
                padding: 10px; /* 移动端减少内边距 */
            }
            
            .sidebar-toggle {
                display: block;
                left: 15px;
            }
            
            .content-container {
                padding: 15px; /* 移动端减少内边距 */
                min-height: auto; /* 移动端取消固定高度 */
                max-width: 100%; /* 移动端使用全宽 */
            }
        }
        
        .navbar-brand {
            color: white !important;
            font-weight: 600;
            padding: 1.2rem 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            align-items: center;
            font-size: 1.3rem;
        }
        
        .navbar-brand i {
            font-size: 1.8rem;
            margin-right: 12px;
            color: var(--secondary-color);
        }
        
        .user-menu {
            position: absolute;
            bottom: 0;
            width: 100%;
            padding: 1.2rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            background: rgba(0, 0, 0, 0.1);
        }
        
        /* 移除用户头像背景色 */
        .user-menu .dropdown-toggle {
            background: transparent !important;
            border: none !important;
        }
        
        .page-header {
            padding-bottom: 15px;
            margin-bottom: 25px;
            border-bottom: 1px solid #eaeaea;
        }
        
        .alert-card {
            border: none;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s, box-shadow 0.3s;
        }
        
        .alert-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }
        
        .table-container {
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
        }
        
        .alert-image {
            border-radius: 6px;
            transition: all 0.3s;
        }
        
        .alert-image:hover {
            box-shadow: 0 0 15px rgba(52, 152, 219, 0.4);
        }
        
        .people-badge {
            display: inline-block;
            padding: 5px 12px;
            border-radius: 20px;
            font-weight: 500;
            background-color: #e1f0fa;
            color: var(--secondary-color);
        }
        
        .pagination .page-item .page-link {
            border-radius: 8px !important;
            margin: 0 3px;
            border: none;
            color: var(--primary-color);
        }
        
        .pagination .page-item.active .page-link {
            background: var(--secondary-color);
            color: white;
        }
        
        /* 自定义滚动条样式 */
        .main-content::-webkit-scrollbar {
            width: 10px;
        }
        
        .main-content::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 10px;
        }
        
        .main-content::-webkit-scrollbar-thumb {
            background: #c1c1c1;
            border-radius: 10px;
        }
        
        .main-content::-webkit-scrollbar-thumb:hover {
            background: #a8a8a8;
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body class="d-flex">
   <div class="sidebar" id="sidebar">
        <div class="d-flex flex-column h-100">
            <a class="navbar-brand d-flex align-items-center" href="/welcome">
                <i class="bi bi-shield-exclamation"></i>
                <span>AI视频分析系统</span>
            </a>
            
            <ul class="nav nav-pills flex-column mt-3 px-2">
                <li class="nav-item">
                    <a href="/ownedit" class="nav-link {% if request.url.path == '/ownedit' %}active{% endif %}">
                        <i class="bi bi-house"></i> 用户:<span id="real-name-display"></span>
                    </a>
                </li>
                <li class="nav-item">
                    <a href="/alerts" class="nav-link {% if request.url.path == '/alerts' %}active{% endif %}">
                        <i class="bi bi-bell"></i> 告警列表
                    </a>
                </li>
                <li class="nav-item">
                    <a href="/devicemanage" class="nav-link {% if request.url.path == '/devicemanage' %}active{% endif %}">
                        <i class="bi bi-bell"></i> 设备管理
                    </a>
                </li>

                <!-- 新增导航项 -->
                <li class="nav-item">
                    <a href="/video-channels/" class="nav-link {% if request.url.path == '/video-channels/' %}active{% endif %}">
                        <i class="bi bi-camera-video"></i> 视频管理通道
                    </a>
                </li>   
                <li class="nav-item">
                    <a href="/areas" class="nav-link {% if request.url.path == '/areas' %}active{% endif %}">
                        <i class="bi bi-map"></i> 区域管理
                    </a>
                </li>
                <!-- <li class="nav-item">
                    <a href="/realtime-preview" class="nav-link {% if request.url.path == '/realtime-preview' %}active{% endif %}">
                        <i class="bi bi-play-circle"></i> 实时预览
                    </a>
                </li> -->
                <li class="nav-item">
                    <a href="/parameterconfig" class="nav-link {% if request.url.path == '/parameterconfig' %}active{% endif %}">
                        <i class="bi bi-sliders"></i> 参数配置
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="/face" class="nav-link {% if request.url.path == '/face' %}active{% endif %}">
                        <i class="bi bi-person-badge"></i> 人脸管理
                    </a>
                </li>
                
                <!-- 修改后的电子围栏菜单项（直接显示） -->
                <li class="nav-item">
                    <a href="/fence/devices" class="nav-link {% if request.url.path == '/fence/devices' %}active{% endif %}">
                        <i class="bi bi-hdd-stack"></i> 电子围栏设备信息
                    </a>
                </li>
                <li class="nav-item">
                    <a href="/efence/alerts" class="nav-link {% if request.url.path == '/efence/alerts' %}active{% endif %}">
                        <i class="bi bi-bell"></i> 电子围栏报警管理
                    </a>
                </li>
                
                <li class="nav-item">
                    <a href="/analysis/result" class="nav-link {% if request.url.path == '/analysis/result' %}active{% endif %}">
                        <i class="bi bi-bell"></i> 预测结果
                    </a>
                </li>
                
                {% if request.cookies["Role"] =="admin" %} 
                <li class="nav-item">
                    <a href="/adminmanage" class="nav-link {% if request.url.path == '/adminmanage' %}active{% endif %}">
                        <i class="bi bi-bar-chart"></i> 用户管理
                    </a>
                </li>
                {% endif %}
                <li class="nav-item">
                    <a href="/logout" class="nav-link {% if request.url.path == '/settings' %}active{% endif %}">
                        <i class="bi bi-gear"></i> 退出系统
                    </a>
                </li>
            </ul>
                </div>
            </div>
           
    
    
    <!-- 移动端侧边栏切换按钮 -->
    <button class="btn btn-primary rounded-circle p-2 sidebar-toggle" id="sidebarToggle">
        <i class="bi bi-list fs-5"></i>
    </button>
    
    <!-- 主内容区域 -->
    <div class="main-content">
        <!-- 顶部消息提示 -->
        <div class="container-fluid mb-3">
            {% if request.query_params.get('success') %}
                <div class="alert alert-success alert-dismissible fade show mt-3">
                    {{ request.query_params.get('success') }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            {% endif %}
            {% if error %}
                <div class="alert alert-danger alert-dismissible fade show mt-3">
                    {{ error }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
            {% endif %}
            {% block messages %}{% endblock %}
        </div>
        
        <!-- 页面内容容器（现在位于最顶端） -->
        <div class="content-wrapper">
            <div class="content-container">
                {% block content %}{% endblock %}
            </div>
        </div>
        
        <!-- 页脚 -->
        <footer class="bg-light py-3 mt-auto">
            <div class="container text-center">
                <p class="mb-0 text-muted">&copy; 2025 告警系统 - 版权所有</p>
            </div>
        </footer>
    </div>

    <!-- Bootstrap JS 和 Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- 自定义JS -->
    <script>
        // 侧边栏切换功能
        document.getElementById('sidebarToggle').addEventListener('click', function() {
            const sidebar = document.getElementById('sidebar');
            sidebar.classList.toggle('show');
        });
        
        // 点击主内容区域关闭侧边栏（移动端）
        document.querySelector('.main-content').addEventListener('click', function(e) {
            const sidebar = document.getElementById('sidebar');
            const sidebarToggle = document.getElementById('sidebarToggle');
            
            if (window.innerWidth <= 992 && sidebar.classList.contains('show') && 
                !sidebar.contains(e.target) && !sidebarToggle.contains(e.target)) {
                sidebar.classList.remove('show');
            }
        });
        
        // 高亮当前导航项
        document.querySelectorAll('.nav-link').forEach(link => {
            if (link.getAttribute('href') === window.location.pathname) {
                link.classList.add('active');
            }
        });
        // 页面加载后解码并显示
        document.addEventListener('DOMContentLoaded', function() {
    const encodedName = "{{ request.cookies.get('RealName', '') }}";
    try {
        const decodedName = decodeURIComponent(encodedName);
        document.getElementById('real-name-display').textContent = decodedName;
    } catch (e) {
        document.getElementById('real-name-display').textContent = encodedName;
    }
});
    </script>
    {% block extra_js %}{% endblock %}
</body>
</html>